<template>
	<view>
		<!-- 搜索框 -->
		<custom_search :bgColor='bgColor'></custom_search>
		
		<!-- 商品列表 -->
		<view class="categories">
			<!-- 左侧一级列表 -->
			<scroll-view scroll-y="true" :style="{height:wh+'px'}" class="left-scroll-view">
				<block v-for="(item,index) in cateList" :key="index">
					<view :class="['left-scroll-view-item',index == active ? 'active' : '']"  @click="changeActive(index)">
						{{item.cat_name}}
					</view>
				</block>
			</scroll-view>
			<!-- 右侧 -->
			<scroll-view :scroll-top="scrollTop" scroll-y="true" :style="{height:wh+'px'}" class="right-scroll-view">
				<!-- 右侧二级列表 -->
				<view class="cate-level2" v-for="(item2,index) in cateLevelTwo" :key="index">
					<view class="cate-level2-item">/{{item2.cat_name}}/</view>
					<!-- 右侧三级列表 -->
					<view class="cate-level3">
						<view class="cate-level3-item" v-for="(item3,index3) in item2.children" :key="index3" @click="getto(item3)">
							<!-- 图片渲染不出来，找个图代替 -->
							<image src="../../static/logo.png" mode=""></image>
							<view class="cate-level3-text">{{item3.cat_name}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {categories} from "@/api/cate_request.js";
	export default {
		data() {
			return {
				scrollTop:0,
				wh:0,
				cateList:[],
				active:0,
				cateLevelTwo:[],
				// bgColor:'#55aaff'
			};
		},
		onLoad() {
			//获取当前系统的信息
			const sysInfo = uni.getSystemInfoSync();
			//窗口的可用高度
			this.wh = sysInfo.windowHeight - 50;
			//调用
			this.getCateGories();
		},
		methods: {
		    async getCateGories(){
				const { data: res } = await categories();
				console.log(res);
				if (res.meta.status !== 200) return uni.$showMsg();
				this.cateList = res.message;
				this.cateLevelTwo = res.message[0].children
			},
			changeActive(index){
				this.active = index;
				this.cateLevelTwo = this.cateList[index].children;
				this.scrollTop = this.scrollTop === 0 ? 1 : 0
			},
			getto(item3){
				uni.navigateTo({
					url:'/fenbao_one/floor_list/floor_list?catId=' + item3.cat_id
				})
			}
		}
	}
</script>

<style lang="scss">
	
.categories{
	display: flex;
	
	.left-scroll-view{
		width: 240rpx;
		text-align: center;
		
		.left-scroll-view-item{
			color: #333333;
			line-height: 120rpx;
			background-color: #F1F1F1;
			
			&.active{
				background-color: #FFFFFF;
				position: relative;
				
				&::before{
					content: '';
					display: block;
					width: 5rpx;
					border-radius: 6rpx;
					height: 50rpx;
					background-color: #fc4353;
					position: absolute;
					left: 5rpx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
	}
	.right-scroll-view{
		
		.cate-level2{
			
			.cate-level2-item{
				font-size: 30rpx;
				text-align: center;
				margin: 15rpx 0;
			}
			.cate-level3{
				width: 100%;
				// height: 300rpx;
				// background-color: #ffff00;
				display: flex;
				flex-wrap: wrap;
				// justify-content: space-between;
				
				.cate-level3-item{
					margin: 10rpx 0;
					width: 33.3%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					// flex-wrap: wrap;
					
					image{
						width: 140rpx;
						height: 140rpx;
						border-radius: 20rpx;
						// background-color: #4CD964;
					}
					
					.cate-level3-text{
						font-size: 30rpx;
						text-align: center;
					}
				}
			}
		}
	}
}
</style>
